package com.elbis.business.entity.messages;

import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import javax.validation.constraints.Size;

import com.elbis.business.entity.DataBaseConstants;
import com.elbis.business.entity.Gamer;

@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = DataBaseConstants.COLUMN_DISCRIMINATOR, discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue(value = DataBaseConstants.DISCRIMINATOR_NOTIFICATION)
@Table(name = DataBaseConstants.TABLE_NOTIFICATION, catalog = DataBaseConstants.CATALOG)
public class Notification implements Serializable {

	private static final long serialVersionUID = -4549352021556863588L;

	private Long id;

	private boolean read;

	@NotNull
	@Past
	private Date time;

	@Size(max = 100)
	private String message;

	@NotNull
	private Gamer owner;

	@NotNull
	private Gamer from;

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = DataBaseConstants.COLUMN_ID, nullable = false)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "is_read", nullable = false, columnDefinition = "TINYINT(1)")
	public boolean isRead() {
		return read;
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	@OneToOne
	@JoinColumn(name = DataBaseConstants.COLUMN_OWNER_ID)
	public Gamer getOwner() {
		return owner;
	}

	public void setOwner(Gamer owner) {
		this.owner = owner;
	}

	@OneToOne
	@JoinColumn(name = DataBaseConstants.COLUMN_FROM_ID)
	public Gamer getFrom() {
		return from;
	}

	public void setFrom(Gamer from) {
		this.from = from;
	}

	public void setRead(boolean read) {
		this.read = read;
	}

}
